﻿
using SHKF.B2C.MeiTuanPeiSong.Model.Dto.Shop;
using SHKF.B2C.MeiTuanPeiSong.Model.Entity.Shop;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
　
namespace SHKF.B2C.MeiTuanPeiSong.BLL
{
    public class ShopBLL : BaseBll
    {
      
        public ShopBLL(SqlSugarClient db) : base(db)
        {
            db.ChangeDatabase("PtE_Mtps_Center");
        }

        public long Save(ShopMtpsEntity shop)
        {
           
            ShopMtpsEntity old = this.db
                .Queryable<ShopMtpsEntity>()
                .Where(oo => oo.shop_id == shop.shop_id)
                .First();

            long SN = 0;
            if (old != null)
            {
                SN = old.SN;
                shop.SN = old.SN;
                this.db
                    .Updateable<ShopMtpsEntity>(shop) 
                    .ExecuteCommand();
            }
            else
            {
                SN = this.db
                    .Insertable<ShopMtpsEntity>(shop)
                    .ExecuteReturnBigIdentity();
            }
             
            return SN;
        }

        public ShopMtpsEntity Get(string shopID)
        {
            ShopMtpsEntity shop = this.db
                .Queryable<ShopMtpsEntity>()
                .Where(oo => oo.shop_id == shopID)
                .First();

            return shop;
        }

        public ShopData GetData(string shopID)
        {  
            ShopData shop = this.db
               .Queryable<ShopMtpsEntity>() 
               .Where(oo => oo.shop_id == shopID)
               .Select(it=> new ShopData())
               .First();

            shop.pay_type_codes = new List<int>();
            foreach (string code in shop.pay_type_code.Split(','))
            {
                shop.pay_type_codes.Add(int.Parse(code));
            } 
            return shop;
        }
    }
}
